package com.cjjd.c.feature.subscribe.near_hotel;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.subscribe.NearbyHotelShowModel;
import com.cjjd.c.utils.DateTimeUtil;
import com.cjjd.c.utils.ImageUtil;
import com.cjjd.c.utils.StringUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ----------------------------------
 * Created by xyd on 2017/11/27.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class HotelNearAdapter extends MyBaseAdapter {

    public HotelNearAdapter(FragmentActivity mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_hotel_near_1, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        NearbyHotelShowModel itemBean = (NearbyHotelShowModel) getItem(position);

        viewHolder.tvHotelName.setText(itemBean.hotelName);
        ImageUtil.displayImage(itemBean.picPath, viewHolder.ivHotelLogo);
        viewHolder.tvPrice.setText("￥" + itemBean.price + "起");
        viewHolder.tvEvaluate.setText(itemBean.hotelScore + "分  " + itemBean.hotelScoreLevel);
        viewHolder.tv_evaluate_2.setText(" " + itemBean.appsCount + "条点评");
        viewHolder.tvHotelStyle.setText(itemBean.starLevel+"星级");
        viewHolder.tvHotelDistance.setText(StringUtil.getDistanceShow(itemBean.dist));
        viewHolder.tvHotelRefreshTime.setText("最新预订：" + DateTimeUtil.getHourBetweenTwoTimes(itemBean.lately, "yyyy-MM-dd HH:mm:ss") + "小时前");

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_hotel_logo)
        ImageView ivHotelLogo;
        @Bind(R.id.tv_hotel_name)
        TextView tvHotelName;
        @Bind(R.id.tv_evaluate)
        TextView tvEvaluate;
        @Bind(R.id.tv_evaluate_2)
        TextView tv_evaluate_2;
        @Bind(R.id.tv_price)
        TextView tvPrice;
        @Bind(R.id.tv_hotel_style)
        TextView tvHotelStyle;
        @Bind(R.id.tv_hotel_distance)
        TextView tvHotelDistance;
        @Bind(R.id.tv_hotel_refresh_time)
        TextView tvHotelRefreshTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
